#  /**
#  * Copyright (c) 2022 Beijing Jiaotong University
#  * PhotLab is licensed under [Open Source License].
#  * You can use this software according to the terms and conditions of the [Open Source License].
#  * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
#  *
#  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
#  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
#  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#  *
#  * See the [Open Source License] for more details.
#  */
#  /**
#  * Author: Zheng Wang
#  * Created: Jun. 27, 2022
#  * Supported by: National Key Research and Development Program of China
#  */

from phot_engine.globals import VerificationError


def _verify_instantiation_parameter(vertex_id, port_id):
    """
        Verify instantiation parameter
    :param vertex_id: str type value represents a vertex
    :param source_port_id: str type value represents a port in a vertex
    :return: verification result
    """
    if isinstance(vertex_id, str) and isinstance(port_id, str):
        return True
    else:
        return False


class Port:
    """
        To describe a port in the GUI
    """

    def __init__(self, vertex_id, port_id):
        if _verify_instantiation_parameter(vertex_id, port_id):
            self.vertex_id = vertex_id
            self.port_id = port_id
        else:
            raise VerificationError("vertex_id and port_id should be str type.")

    def __repr__(self):
        return "Port:(vertex id:{},port id:{})".format(self.vertex_id, self.port_id)

    def __eq__(self, other):
        if isinstance(other, self.__class__):
            if self.vertex_id == other.vertex_id and self.port_id == other.port_id:
                return True
            else:
                return False
        else:
            raise TypeError("unsupported operand type(s) for ==: {} and {}".format(type(self), type(other)))
